package com.example.wechat114.service.impl;

import com.example.wechat114.commons.JsonBean;
import com.example.wechat114.entity.GForm;
import com.example.wechat114.mapper.GFormMapper;
import com.example.wechat114.service.GFormService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class GFormServiceImpl implements GFormService {

    @Autowired
    private GFormMapper gFormMapper;

    @Override
    public JsonBean addGForm(GForm gForm) {
        JsonBean jsonBean = new JsonBean(-1, "", null);
        gForm.setGnum(10);
        gForm.setUpnum(5);
        gForm.setDownnum(5);
        for (int i = 1; i <= 38 ; i++ ){
            gForm.setMid(i);
            int ii = gFormMapper.insertSelective(gForm);
            if(ii>0){
                jsonBean = new JsonBean(0,"",null);
            }
        }


        return jsonBean;
    }

    @Override
    public JsonBean selectOne(GForm gForm) {
        return new JsonBean(0,"",gFormMapper.selectOneGForm(gForm));
    }

    @Override
    public JsonBean updateGform(GForm gForm,String status1) {
        JsonBean jsonBean = new JsonBean(-1,"" ,null);
        int i = -1;
        if(status1.equals("1")){
            if(gForm.getUpnum()>0) {
                gForm.setUpnum(gForm.getUpnum() - 1);
                i = gFormMapper.updateUpnum(gForm);
            }
        }else if(status1.equals("2")){
            if(gForm.getDownnum()>0) {
                gForm.setDownnum(gForm.getDownnum() - 1);
                i = gFormMapper.updateUpnum(gForm);
            }
        }

        if(i>0){
            jsonBean = new JsonBean(0,"",null);
        }
        return jsonBean;
    }


}
